package com.wly.dbc.parser;

import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.wly.datapool.skillpool.skill.SkillStatic;
import com.wly.datapool.soldierpool.SoldierPool;
import com.wly.datapool.soldierpool.SoldierStatic;
import com.wly.define.IDZoneDefine;
import com.wly.define.ParserDefine;

public class SoldierParser extends BaseParser
{
	SoldierPool _soldierPool = SoldierPool.getInstance();
	public SoldierParser()
	{
		// TODO Auto-generated constructor stub
	}

	@Override
	public int getParserId()
	{
		// TODO Auto-generated method stub
		return ParserDefine.SOLDIER_PARSER;
	}

	@Override
	public String getXmlFileName()
	{
		// TODO Auto-generated method stub
		return "soldier.xml";
	}

	@Override
	public void doParser(Document doc)
	{
		// TODO Auto-generated method stub
		try
		{
			SoldierStatic soldier;
			NodeList nl = doc.getElementsByTagName("soldier");
			Node nodeTmp;
			NamedNodeMap attrs;
			for (int i = 0; i < nl.getLength(); i++)
			{
				soldier = new SoldierStatic();
				attrs = nl.item(i).getAttributes();
				soldier.id      = Integer.parseInt(attrs.getNamedItem("templateId").getNodeValue())+IDZoneDefine.SOLDIER_START_ID;
				soldier.name    = attrs.getNamedItem("name").getNodeValue();
				soldier.desc    = attrs.getNamedItem("desc").getNodeValue();
				soldier.type    = Integer.parseInt(attrs.getNamedItem("soldierType").getNodeValue());
				soldier.level   = Integer.parseInt(attrs.getNamedItem("soldierLv").getNodeValue());
				soldier.attack  = Integer.parseInt(attrs.getNamedItem("attack").getNodeValue());
				soldier.defense = Integer.parseInt(attrs.getNamedItem("defence").getNodeValue());
				soldier.maxHp   = Integer.parseInt(attrs.getNamedItem("hp").getNodeValue());
				soldier.campLevelReq = Integer.parseInt(attrs.getNamedItem("barracksLv").getNodeValue());
				soldier.price   = Integer.parseInt(attrs.getNamedItem("soldierPrice").getNodeValue());
				_soldierPool.addSoldier(soldier);
			}
		} 
		catch (Exception e)
		{
			e.printStackTrace();
		}
		
	}

}
